home *** CD-ROM | disk | FTP | other *** search
/ El Mac 9 / El Mac 9.iso / Shareware / Demos / Igor Demo Pro / 1 PutContentsIn Igor Pro Folder / WaveMetrics Procedures / Graphing / Split Axis < prev    next >
Encoding:
Text File  |  1996-01-30  |  5.7 KB  |  214 lines  |  [TEXT/IGR0]

  1. // Split Axis, Version 1.1, LH951107
  2. // See the Split Axis Example experiment for documentation
  3.  
  4. // Version 1.1 created to be liberal name aware and data folder savvy
  5.  
  6. #include <Keyword-Value>
  7. #include <Readback ModifyStr>
  8. #include <Graph Utility Procs>
  9.  
  10.  
  11. #pragma rtGlobals=1        // This mainly acts as notice that this proc is Igor 3.0 savvy
  12.  
  13.  
  14. Macro SplitAxis(axName,splitPoint,splitGap)
  15.     String axName="left"
  16.     Prompt axName,"axis to split",popup AxisList("")
  17.     Variable splitPoint= 80
  18.     Prompt splitPoint,"% along axis to place split"
  19.     Variable splitGap= 8
  20.     Prompt splitGap,"Size of gap in Points"
  21.     
  22.     DoSplitAxis(axName,splitPoint/100,splitGap)
  23. End
  24.  
  25. // this routine finds the last trace on the top graph. It is used right
  26. // after appending a new trace to a graph to find out the full trace name
  27. // of that new trace. The wave name alone is not sufficient.
  28. // This routine ASSUMES the last trace is not the only trace
  29. //
  30. Function/S WMSA_GetLastTraceName()        // funny name to avoid any possible future conflict
  31.     Variable p0,p1    // for walking down the list
  32.     Variable semicolon= char2num(";")
  33.  
  34.     String list=TraceNameList("", ";", 1)
  35.     p1= strlen(list)-2                            // index of last char before semicolon
  36.     p0= p1-1
  37.     do
  38.         if( char2num(list[p0]) == semicolon )
  39.             break
  40.         endif
  41.         p0-=1
  42.     while(p0>0)        // emergency exit only
  43.             
  44.     return list[p0+1,p1]
  45. end
  46.  
  47.  
  48.  
  49. Proc DoSplitAxis(axName,splitPoint,splitGap)
  50.     String axName;Variable splitPoint,splitGap
  51.     
  52.     PauseUpdate; Silent 1
  53.  
  54.     String newAxis
  55.     Variable i=2
  56.     do
  57.         newAxis= axName+"_P"    +num2istr(i)    | name of new axis; left_P2
  58.         if( strlen(AxisInfo("",newAxis)) == 0 )
  59.             break;
  60.         endif
  61.         i+=1
  62.     while(1)
  63.  
  64.     String axInfo= AxisInfo("",axName),axType
  65.     axType= StrByKey("AXTYPE",axInfo)
  66.     if( strlen(axType) == 0 )
  67.         Abort "FOOBAR"                        | sanity check, from now on we ASSUME things work
  68.     endif
  69.     Variable isX= (CmpStr("bottom", axType)==0 ) %|  (CmpStr("top", axType)==0 )
  70.  
  71.     String tracesOnGraph= TraceNameList("", ";", 1)
  72.     String thetrace,tInfo,otheraxis,oaInfo,oaType
  73.     String theCmd                            | command string is built up here
  74.     String key1,key2
  75.     Variable/D av0,av1,sp
  76.     Variable origStart,origEnd,split            | original axis start and end fractions, split point on axis
  77.     
  78.     GetAxis/Q $axName
  79.     av0= V_Min; av1= V_max
  80.     
  81.     i=0
  82.     do
  83.         thetrace= GetStrFromList(tracesOnGraph,i,";")
  84.         if( strlen(thetrace) == 0 )
  85.             break;
  86.         endif
  87.         
  88.         tInfo= TraceInfo("",thetrace,0)
  89.         if( isX )
  90.             key1= "XAXIS"
  91.             key2= "YAXIS"
  92.         else
  93.             key1= "YAXIS"
  94.             key2= "XAXIS"
  95.         endif
  96.         if( CmpStr(axName,StrByKey(key1,tInfo))== 0 )
  97.             otheraxis= StrByKey(key2,tInfo)
  98.             oaInfo=  AxisInfo("",otheraxis)
  99.             oaType= StrByKey("AXTYPE",oaInfo)
  100.             theCmd= "AppendToGraph/"+oaType[0]+"="+otheraxis+"/"+axType[0]+"="+newAxis+" "
  101.             theCmd += GetWavesDataFolder(TraceNameToWaveRef("", thetrace), 4)
  102.             if( strlen(StrByKey("XWAVE",tInfo)) != 0 )
  103.                 theCmd += " vs "+GetWavesDataFolder(XWaveRefFromTrace("", thetrace), 4)
  104.             endif
  105.             Execute theCmd
  106.             CopyTraceSettings(thetrace,-1,WMSA_GetLastTraceName(),-1)
  107.         endif
  108.             
  109.         I+=1
  110.     while(1)
  111.     CopyAxisSettings(axName,newAxis)
  112.     origStart= GetNumFromModifyStr(axInfo,"axisEnab","{",0)
  113.     origEnd= GetNumFromModifyStr(axInfo,"axisEnab","{",1)
  114.     sp= splitPoint*(av1-av0)+av0
  115.  
  116.     GetWindow kwTopWin,psize
  117.     if( isX )
  118.         splitGap= splitGap/(2*(V_right-V_left))
  119.     else
  120.         splitGap= splitGap/(2*(V_bottom-V_top))
  121.     endif
  122. |    splitGap *= origEnd-origStart
  123.  
  124.     split= splitPoint*(origEnd-origStart)+origStart
  125.     if( splitPoint < 0.5 )                | leave original axis with biggest piece
  126.         SetAxis $axName,sp,av1
  127.         SetAxis $newAxis,av0,sp
  128.         ModifyGraph axisEnab($axName)={split+splitGap,origEnd}
  129.         ModifyGraph axisEnab($newAxis)={origStart,split-splitGap}
  130.     else
  131.         SetAxis $axName,av0,sp
  132.         SetAxis $newAxis,sp,av1
  133.         ModifyGraph axisEnab($axName)={origStart,split-splitGap}
  134.         ModifyGraph axisEnab($newAxis)={split+splitGap,origEnd}
  135.     endif
  136.     ModifyGraph standoff($axName)=0, freePos($axName)=0
  137.     ModifyGraph standoff($newAxis)=0, freePos($newAxis)=0
  138. end
  139.  
  140.  
  141. Macro AddSplitAxisMarks(axName1,axName2)
  142.     String axName1="left",axName2= "left_P2"
  143.     Prompt axName1,"axis 1",popup AxisList("")
  144.     Prompt axName2,"axis 2",popup AxisList("")
  145.     
  146.     DoAddSplitAxisMarks(axName1,axName2)
  147. End
  148.  
  149.  
  150.  
  151. Proc DoAddSplitAxisMarks(axName1,axName2)
  152.     String axName1,axName2
  153.     
  154.     PauseUpdate; Silent 1
  155.  
  156.     Variable SLASH_LEN= 5,SLASH_HEIGHT=2        | these params determine size and angle of slash
  157.     String axInfo1= AxisInfo("",axName1),axInfo2= AxisInfo("",axName2)
  158.     String axType1,axType2
  159.     axType1= StrByKey("AXTYPE",axInfo1)
  160.     axType2= StrByKey("AXTYPE",axInfo2)
  161.     if( CmpStr(axType1,axType2)!= 0 )
  162.         Abort "Different kinds of axes - unlikely"        | sanity check
  163.     endif
  164.     Variable isX= (CmpStr("bottom", axType1)==0 ) %|  (CmpStr("top", axType1)==0 )
  165.  
  166.     Variable a1start,a2start,a1end,a2end
  167.     
  168.     a1start= GetNumFromModifyStr(axInfo1,"axisEnab","{",0)
  169.     a1end= GetNumFromModifyStr(axInfo1,"axisEnab","{",1)
  170.     a2start= GetNumFromModifyStr(axInfo2,"axisEnab","{",0)
  171.     a2end= GetNumFromModifyStr(axInfo2,"axisEnab","{",1)
  172.     if( a1end > a2start )        | user chose axes in reverse order
  173.         a1end= a2end
  174.         a2start= a1start
  175.     endif
  176.     GetWindow kwTopWin,psize
  177.     Variable x0= V_left, y0= V_top,dx= V_right-V_left,dy= V_bottom-V_top,x,y
  178.     Variable sh,sl
  179.  
  180.     SetDrawLayer UserFront
  181.     SetDrawEnv gstart
  182.     if( isX )
  183.         x= a1end
  184.         if( CmpStr("bottom", axType1)==0 )
  185.             y= 1
  186.         else
  187.             y= 0
  188.         endif
  189.         sh= SLASH_HEIGHT/dx
  190.         sl= SLASH_LEN/dy
  191.         SetDrawEnv xcoord= prel,ycoord= prel
  192.         DrawLine x-sh,y-sl,x+sh,y+sl
  193.         x= a2start
  194.         SetDrawEnv xcoord= prel,ycoord= prel
  195.         DrawLine x-sh,y-sl,x+sh,y+sl
  196.     else
  197.         y= 1-a1end
  198.         if( CmpStr("right", axType1)==0 )
  199.             x= 1
  200.         else
  201.             x= 0
  202.         endif
  203.         sh= SLASH_HEIGHT/dy
  204.         sl= SLASH_LEN/dx
  205.         SetDrawEnv xcoord= prel,ycoord= prel
  206.         DrawLine x-sl,y-sh,x+sl,y+sh
  207.         y= 1-a2start
  208.         SetDrawEnv xcoord= prel,ycoord= prel
  209.         DrawLine x-sl,y-sh,x+sl,y+sh
  210.     endif
  211.     SetDrawEnv gstop
  212. end
  213.  
  214.